home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Modules / BackSpaceModules / Source / BattleView / Ship.m < prev    next >
Text File  |  1994-05-04  |  5KB  |  160 lines

  1. /* Ship.m -- implementation for ship objects
  2.    Copyright (C) 1992, 1993 David A. Strout
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Written by David Strout <dstrout@isi.edu>. */
  19.  
  20.  
  21. #import "Ship.h"
  22. #import "Thinker.h"
  23.  
  24. @implementation Ship
  25.  
  26. - initOnSide:(int)side
  27. /* This is nasty.  Better to have the ships on each side be subclasses of Ship. */
  28. {
  29.   INITRAND;
  30.   [super init];
  31.   
  32.   [(explosion[0] = [self findImageNamed:"Exp0"]) setScalable:NO];
  33.   [(explosion[1] = [self findImageNamed:"Exp1"]) setScalable:NO];
  34.   [(explosion[2] = [self findImageNamed:"Exp2"]) setScalable:NO];
  35.   [(explosion[3] = [self findImageNamed:"Exp3"]) setScalable:NO];
  36.   [(explosion[4] = [self findImageNamed:"Exp4"]) setScalable:NO];
  37.   [(explosion[5] = [self findImageNamed:"Exp5"]) setScalable:NO];
  38.   [(explosion[6] = [self findImageNamed:"Exp6"]) setScalable:NO];
  39.   [(explosion[7] = [self findImageNamed:"Exp7"]) setScalable:NO];
  40.   
  41.   
  42.   if(side==FED) {
  43.     [(ship[NORTH] = [self findImageNamed:"Fed0"]) setScalable:NO];
  44.     [(ship[NEAST] = [self findImageNamed:"Fed1"]) setScalable:NO];
  45.     [(ship[EAST] = [self findImageNamed:"Fed2"]) setScalable:NO];
  46.     [(ship[SEAST] = [self findImageNamed:"Fed3"]) setScalable:NO];
  47.     [(ship[SOUTH] = [self findImageNamed:"Fed4"]) setScalable:NO];
  48.     [(ship[SWEST] = [self findImageNamed:"Fed5"]) setScalable:NO];
  49.     [(ship[WEST] = [self findImageNamed:"Fed6"]) setScalable:NO];
  50.     [(ship[NWEST] = [self findImageNamed:"Fed7"]) setScalable:NO];
  51.   }
  52.   else { /* side == Klingon */
  53.     [(ship[NORTH] = [self findImageNamed:"Kli0"]) setScalable:NO];
  54.     [(ship[NEAST] = [self findImageNamed:"Kli1"]) setScalable:NO];
  55.     [(ship[EAST] = [self findImageNamed:"Kli2"]) setScalable:NO];
  56.     [(ship[SEAST] = [self findImageNamed:"Kli3"]) setScalable:NO];
  57.     [(ship[SOUTH] = [self findImageNamed:"Kli4"]) setScalable:NO];
  58.     [(ship[SWEST] = [self findImageNamed:"Kli5"]) setScalable:NO];
  59.     [(ship[WEST] = [self findImageNamed:"Kli6"]) setScalable:NO];
  60.     [(ship[NWEST] = [self findImageNamed:"Kli7"]) setScalable:NO];
  61.   };
  62.   
  63.   [(backGround =[self findImageNamed:"back"]) setScalable:NO];
  64.   
  65.   [self beginLife];
  66.  
  67. /* Separate them at the begining, since random is being lazy at this point */
  68.   if(side==FED) location.x=0;
  69.   if(side==KLI) location.x=maxX;
  70.  
  71.   return self;
  72. }
  73.  
  74. - beginLife
  75. /* After we explode, or at the start, set ourselves up */
  76. {
  77.   [self newVector];
  78.   location.x=RANDINT(11)*100;location.y=RANDINT(8)*100;
  79.   damage=MAX_DAM;
  80.   status=OK;
  81.   return self;
  82. }
  83.  
  84. - drawSelf
  85. /* This simply composites the right image at location.  That means that someone else has already done the lockFocus, and will do the unlockFocus & flushing. */
  86. {
  87.   
  88.   [backGround composite:NX_SOVER toPoint:&location]; /* Erase old one */
  89.   
  90.   if(status==OK) {    
  91.     switch(heading) {
  92.     case NORTH: 
  93.       location.y+=speed; 
  94.       break; 
  95.     case SOUTH: 
  96.       location.y-=speed; 
  97.       break; 
  98.     case EAST: 
  99.       location.x+=speed;
  100.       break; 
  101.     case WEST: 
  102.       location.x-=speed;
  103.       break; 
  104.     case NEAST: 
  105.       location.x+=speed;
  106.       location.y+=speed; 
  107.       break;
  108.     case SEAST: 
  109.       location.x+=speed;
  110.       location.y-=speed; 
  111.       break;
  112.     case SWEST: 
  113.       location.x-=speed;
  114.       location.y-=speed; 
  115.       break;
  116.     case NWEST: 
  117.       location.x-=speed;
  118.       location.y+=speed; 
  119.       break;
  120.     };
  121.   };
  122.   
  123.   switch(status) {
  124.   case OK:
  125.     [ship[heading] composite:NX_SOVER toPoint:&location];
  126.     break;
  127.   case EXPLODE0:
  128.   case EXPLODE1:
  129.   case EXPLODE2:
  130.   case EXPLODE3:
  131.   case EXPLODE4:
  132.   case EXPLODE5:
  133.   case EXPLODE6:
  134.   case EXPLODE7:
  135.     [explosion[status] composite:NX_SOVER toPoint:&location];
  136.     status++;
  137.     break;
  138.   case DEAD: /* Game over, dude.  Galactic Toast.  Krispy Klingons. */
  139.     [self beginLife];
  140.   };
  141.   
  142.   return self;
  143. }
  144.  
  145.  
  146. - takeHitForPoints:(int)num
  147. {
  148.   damage-=num;
  149.   [self newVector]; /* Try to dodge */
  150.   if((damage<=0) && (status==OK)) status=EXPLODE0;
  151.   return self;
  152. }
  153.  
  154. - (int)damage;
  155. {
  156.   return damage;
  157. }
  158.  
  159. @end
  160.